<% layout('/layout/default.html', {title: '定时任务', libs: ['layui','icheck']}){ %>
<div class="main-content">
	<div class="card-header">
		<i class="fa fa-sitemap"></i> 定时任务管理
		<div class="header-tools float-right">
			<a href="#" class="btn btn-default btn-sm" id="btnSearch" title="查询"><i class="fa fa-filter"></i> 查询</a>
			<% if(hasPermi('sys:job:edit')){ %>
			<a href="/sys/job/form" class="btn btn-default btn-sm btnTool" title="任务添加"><i class="fa fa-plus"></i>添加</a>
			<% } %>
		</div>
	</div>
	<div class="container-fluid">
		<form id="searchForm" action="${ctx}/sys/job/listAll" class="form-inline d-none">
			<div class="form-group">
				<label class="control-label">任务类名：</label>
				<div class="control-inline">
					<input name="jobClassName" class="form-control form-control-sm"/>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label">任务所在组：</label>
				<div class="control-inline">
					<input name="jobGroupName" class="form-control form-control-sm"/>
				</div>
			</div>
			<div class="form-group">
				<button type="submit" class="btn btn-success btn-sm">查询</button>
				<button type="reset" class="btn btn-default btn-sm">重置</button>
			</div>
		</form>
		<table id="btGrid" class="table table-bordered table-hover" cellspacing="0" width="100%"></table>
	</div>
</div>
<% } %>
<script>
//初始化layui-table对象
	$('#btGrid').BTGrid({
		searchForm: $("#searchForm"),
		columnModel: [
			{title:'任务类名', field:'jobClassName'},
            {title:'任务所在组', field:'jobGroupName'},
            {title:'表达式', field:'cronExpression'},
			{title:'上次执行时间', templet: function (row) {
					if (row.prevFireTime){   // data不为空进行转换
						return (new Date(row.prevFireTime)).Format("yyyy-MM-dd hh:mm:ss");
					} else {
						return ''; //data为空时不转换
					}
				}},
			{title:'下次执行时间', templet: function (row) {
				if (row.nextFireTime){   // data不为空进行转换
					return (new Date(row.nextFireTime)).Format("yyyy-MM-dd hh:mm:ss");
				} else {
					return ''; //data为空时不转换
				}
			}},
            {title:'状态', templet: function(row){
                    return js.transDictLabel(${@DictUtils.getDictListJson('sys_job_status')}, row.triggerState, '未知');
             }},
			{title:'操作', templet: function(row){
				var actions = [];
                var operate = row.triggerState=="PAUSED"?'<a href="${ctx}/sys/job/resume?jobClassName='+row.jobClassName+'&jobGroupName='+row.jobGroupName+'" class="btn btn-xs btn-success btnList" title="恢复" data-confirm="确认要恢复任务吗？"><i class="fa fa-play"></i></a>&nbsp&nbsp':
                    	      '<a href="${ctx}/sys/job/pause?jobClassName='+row.jobClassName+'&jobGroupName='+row.jobGroupName+'" class="btn btn-xs btn-success btnList" title="暂停" data-confirm="确认要暂停任务吗？"><i class="fa fa-pause"></i></a>&nbsp&nbsp'
                <% if(hasPermi('sys:dict:edit')){ %>
					actions.push(operate);
                    actions.push('<a href="/sys/job/resetform?jobClassName='+row.jobClassName+'&jobGroupName='+row.jobGroupName+'&cronExpression='+row.cronExpression+'" class="btn btn-xs btn-primary btnList" title="重置任务"><i class="far fa-edit"></i></a>&nbsp&nbsp');
                    actions.push('<a href="${ctx}/sys/job/del?jobClassName='+row.jobClassName+'&jobGroupName='+row.jobGroupName+'" class="btn btn-xs btn-danger btnList" title="删除" data-confirm="确认要删除定时任务吗?"><i class="far fa-trash-alt"></i></a>');
				<% } %>
				return actions.join('');
			}}
		],
		// 加载成功后执行事件
		ajaxSuccess: function(data){
			
		}
	});
</script>